package com.example.quartz.job;

import lombok.extern.slf4j.Slf4j;
import org.quartz.*;

@Slf4j
//禁止并发执行同一个job，只有当当前job执行完成才可以执行下一个同一个job
@DisallowConcurrentExecution
//用于持久化JobDataMap，当前job执行的执行完之后，向下一次执行该job时，传递信息需要用到此项
@PersistJobDataAfterExecution
public class CustomJob implements Job {
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
        JobDataMap triggerDataMap = context.getTrigger().getJobDataMap();
        JobDataMap mergedJobDataMap = context.getMergedJobDataMap();
        log.info("jobDataMap:{}",jobDataMap.getString("JOB_KEY"));
        log.info("jobDataMap.time:{}",jobDataMap.getInt("time"));
        log.info("triggerDataMap:{}",triggerDataMap.getString("TRIGGER_KEY"));
        log.info("mergedJobDataMap.JOB_KEY:{}",mergedJobDataMap.getString("JOB_KEY"));
        log.info("mergedJobDataMap.TRIGGER_KEY:{}",mergedJobDataMap.getString("TRIGGER_KEY"));

        /*测试持久化:PersistJobDataAfterExecution*/
        jobDataMap.put("time",(Integer) jobDataMap.get("time")+1);
    }
}
